Академический Документы
Профессиональный Документы
Культура Документы
Notebook: Robotics
Created: 4/16/2020 11:37 AM Updated: 4/19/2020 8:50 PM
Author: Criscela Ysabelle
Tags: homework
LIGHT SENSOR
phototransistor
also called
analog sensor
detects amount of light present
returns an ANALOG value
REVIEW FROM PREVIOUS LESSON: analog -
( a value in between the minimum
and maximum; unlike digital signals that only return 1 or 0)
int ledPin=9;
int lightSensorPin=A1;
void setup()
{
//nothing here
}
void loop()
{
int lightSensorValue=analogRead(lightSensorPin);
int ledValue=map(lightSensorValue,0,1023,0,255);
analogWrite(ledPin, ledValue);
delay(10);
}
SENSOR CALIBRATION
sensors are ALWAYS dependent on environmental conditions
light sensors rely on the amount of light present in its current surroundings
are subject to change in different settings
THUS, sensors need to be calibrated when changing locations/conditions
(ex.) If your light sensor responds accordingly when in good lighting conditions, and
you suddenly transport it to a place with low light, your code will not work the way it
used to. The supposed reading for when your light sensor is covered, and for when it
isn't, will only be read as your light sensor ALWAYS being covered because your light
sensor is constantly in low light.
To adjust to this, you must calibrate your sensor to adapt to the new setting.
Calibration Example
Similar to the earlier example, the LED responds to the light sensor value.
It will turn on if the light sensor is covered, and turn off if it isn't.
If it doesn't work properly, turn the potentiometer knob until it does.
How it's done:
Similar to the first example, the activity of your LED will be reliant on
your light sensor's readings - except, this time, your LED will switch on
and off depending on the light sensor reading value.
A potentiometer will be used for calibration purposes.
Materials:
Same circuit from earlier
Potentiometer (1)
Jumper wires (3)
Assembly:
int ledPin=9;
int lightSensorPin=A1;
int potPin=A5;
void setup()
{
pinMode(ledPin,OUTPUT);
}
void loop()
{
int lightSensorValue=analogRead(lightSensorPin);
int threshold=analogRead(potPin);
if(lightSensorValue>threshold)
{
digitalWrite(ledPin,LOW);
}
else
{
digitalWrite(ledPin,HIGH);
}
delay(10);
}
SERIAL PORT
enables a control board to communicate with a computer via USB connection
can be used to exchange complicated data w/computer
can send or receive text , instead of only digital or analog signals
can also communicate with OTHER softwares
(ex.) pressing a button on the board can cause the color of the screen in a
sketch (in the Processing software) to change
the board sends the data re.: the state of the button
(pressed/unpressed)
the computer receives the data and responds to it by changing
the color
uses the DIGITAL 0
pins and 1.
0
Pin : RX or receiver; the board RECEIVES data, or
1
Pin : TX or transmitter; the board SENDS the data.
FOOTNOTE:
Hello Miss! Sorry po if the layouting (indentation, etc.) is a bit weird; I made this file with
Evernote. I tried to transfer it to Word after I finished, but it looked even worse.
Thank you po, and I hope you and your family stay safe!
Best regards,
Criscela Ysabelle