//Program by Jeremy Blum
//www.jeremyblum.com
//This will turn on an LED after a threshold
int sensePin = 0;
int ledPin = 9;
void setup()
{
//Note: We don't need to specifiy sensePin as an
//input, since it defaults to that when we read it
//The LED pin needs to be set as an output
pinMode(ledPin, OUTPUT);
//This is the default value, but we can set it anyways
analogReference(DEFAULT); //5V Reference on UNO
}
void loop()
{
// read the sensor
int val = analogRead(sensePin);
if(val < 800)
{
digitalWrite(ledPin, HIGH);
}
else
{
digitalWrite(ledPin, LOW);
}
}
---------------------------------------------
//www.jeremyblum.com
//This will turn on an LED after a threshold
int sensePin = 0;
int ledPin = 9;
void setup()
{
//Note: We don't need to specifiy sensePin as an
//input, since it defaults to that when we read it
//The LED pin needs to be set as an output
pinMode(ledPin, OUTPUT);
//This is the default value, but we can set it anyways
analogReference(DEFAULT); //5V Reference on UNO
}
void loop()
{
// read the sensor
int val = analogRead(sensePin);
if(val < 800)
{
digitalWrite(ledPin, HIGH);
}
else
{
digitalWrite(ledPin, LOW);
}
}
------------------------------------
//www.jeremyblum.com
//Turn on an LED if a room is dim, and motion is detected
//Define Pins
int motionPin = 0;
int lightPin = 1;
int ledPin = 9;
//Distance Variables
int lastDist = 0;
int currentDist = 0;
//Threshold for Movement
int thresh = 200;
void setup()
{
//The LED pin needs to be set as an output
pinMode(ledPin, OUTPUT);
}
void loop()
{
// read the sensor
int lightVal = analogRead(lightPin);
currentDist = analogRead(motionPin);
//Does the current distance deviate from the last distance by more than the threshold?
if ((currentDist > lastDist + thresh || currentDist < lastDist - thresh) && lightVal < 800)
{
digitalWrite(ledPin, HIGH);
delay(1000);
}
else
{
digitalWrite(ledPin, LOW);
}
lastDist = currentDist;
}
---------------------------------------------
//www.jeremyblum.com
//Reads and analog sensor and displays the value
int sensePin = 0;
void setup()
{
//Note: We don't need to specifiy sensePin as an
//input, since it defaults to that when we read it
//This is the default value, but we can set it anyways
analogReference(DEFAULT); //5V Reference on UNO
//Allows us to listen to serial communications from the arduino
Serial.begin(9600);
}
void loop()
{
// print the button state to a serial terminal
Serial.println(analogRead(sensePin));
delay(500);
//wait half a second, then print again.
}
Nenhum comentário:
Postar um comentário