int photodiode
=
A0
;
// The A0 pin,read Photodiode
int motor
=
6
;
// The 6 pin,driving the motor
void setup
()
{
pinMode
(
photodiode
,
INPUT
)
;
// initialize the photodiode pin as an input.
pinMode
(
motor
,
OUTPUT
)
;
// initialize the motor pin as an output.
}
void loop
()
{
int speed
=
analogRead
(
photodiode
)
/
2
;
//because the read max value is 512
analogWrite
(
motor
,
speed
)
;
//According to the intensity of light motor speed control
}
Part6. Soil moisture sensor control relay
/*
PART6 Soil moisture Sensor CONTROL Relay
According to the intensity of light motor speed control
*/
int soil
=
A0
;
// The A0 pin,read Soil moisture
int relay
=
6
;
// The 6 pin,driving the Relay
void setup
()
{
pinMode
(
soil
,
INPUT
)
;
// initialize the soil pin as an input.
pinMode
(
relay
,
OUTPUT
)
;
// initialize the relay pin as an output.
}
void loop
()
{
int value
=
analogRead
(
soil
)
;
if
(
value
>
200
){
//set the default value ,you can set it then more or less to do something
digitalWrite
(
relay
,
HIGH
)
;
//turn on the relay
}
else
digitalWrite
(
relay
,
LOW
)
;
//turn off the relay
}
Содержание Arduino Starter Kit
Страница 8: ......