Animal Cut Files
void setup() {
Serial.begin(9600);
pinMode(13, OUTPUT);
pinMode(8, INPUT_PULLUP);
}
void loop() {
if (digitalRead(8) == false) {
digitalWrite(13, HIGH);
}
else {
digitalWrite(13, LOW);
}
delay(30);
}
void setup() {
Serial.begin(9600);
pinMode(13, OUTPUT);
pinMode(A0, INPUT_PULLUP);
}
void loop() {
int brightness = analogRead(A0);
if (brightness >= 400) {
digitalWrite(13, HIGH);
}
else {
digitalWrite (13, LOW);
}
Serial.println(brightness);
}
Ultrasonic sensors are distance sensors that use sound waves to detect how far away an object is. They send out high frequency bursts of sound and listen for its echo. They then determine how far away the object is based on how long it takes for the sound to return to the sensor. This variety requires an Arduino library to operate.
#include <NewPing.h>
#include <Servo.h>
Servo myservo; // create servo object to control a servo
NewPing mysensor(5, 6, 200);
void setup() {
myservo.attach(11); // attaches the servo on pin 9 to the servo object
Serial.begin(9600);
}
void loop() {
int pingTime = mysensor.ping();
int distance = mysensor.ping_in();
int distance_cm = mysensor.ping_cm();
if (distance < 2){
myservo.write(179);
}
else{
myservo.write(0);
}
Serial.println(distance);
}
PIR sensors (or passive infrared sensors) are motion sensors that measure subtle changes in infrared light in the room and register that change as movement. The processing is done on the chip and it outputs a current based on whether or not it detects motion.
int pin = 2; void setup(){ pinMode(pin, INPUT); pinMode(13, OUTPUT); } void loop(){ int pirVal = digitalRead(pin); if (pirVal == 0) { digitalWrite(13, HIGH); } else { digitalWrite(13, LOW); } delay(100); }
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
void setup() {
myservo.attach(11); // attaches the servo on pin 9 to the servo object
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
//remap sensorValue from 0-1024 to 0-255
pos = map(sensorValue, 0, 1024, 0, 179);
// tell servo to go to position in variable 'pos'
myservo.write(pos);
// print the value of variable "pos"
Serial.println(pos);
}
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
void setup() {
myservo.attach(11); // attaches the servo on pin 9 to the servo object
}
void loop() {
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
void setup() {
myservo.attach(11); // attaches the servo on pin 9 to the servo object
}
void loop() {
myservo.write(45); // tell servo to go to position 45 Degrees
}