0% found this document useful (0 votes)
19 views7 pages

Exercice 1: Void Setup (Serial - Begin (9600) ) Void Loop (Serial - Println ("Bonjour") Delay (2000) )

The document contains 3 coding exercises that use sensors and Arduino. Exercise 1 involves printing messages to the serial monitor on a delay and detecting button presses. Exercise 2 uses a DHT sensor to measure humidity and trigger a buzzer if humidity is over 80%. Exercise 3 also uses a DHT sensor to measure temperature, and triggers a motor and LEDs depending on the temperature reading.

Uploaded by

Mohamed Toujga
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views7 pages

Exercice 1: Void Setup (Serial - Begin (9600) ) Void Loop (Serial - Println ("Bonjour") Delay (2000) )

The document contains 3 coding exercises that use sensors and Arduino. Exercise 1 involves printing messages to the serial monitor on a delay and detecting button presses. Exercise 2 uses a DHT sensor to measure humidity and trigger a buzzer if humidity is over 80%. Exercise 3 also uses a DHT sensor to measure temperature, and triggers a motor and LEDs depending on the temperature reading.

Uploaded by

Mohamed Toujga
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Exercice 1

Q1-

void setup() {

Serial.begin(9600);

void loop() {

Serial.println("Bonjour");

delay(2000);

}
Q2-

int bouton=5;

void setup() {

pinMode(bouton,INPUT_PULLUP);

Serial.begin(9600);

void loop() {

if(digitalRead(bouton)==LOW){

Serial.println("Bouton appuyé");

else

Serial.println("Bouton relâché");

} }
Q3-

void setup() {

Serial.begin(9600);

void loop() {

int sensorValue = analogRead(A0);

Serial.println(sensorValue);

delay(500);

}
Exercice 2

#include <DHT.h>

#define DHTPIN 12

#define DHTTYPE DHT22

DHT dht(DHTPIN, DHTTYPE);

int buzzer=4;

void setup()

Serial.begin(9600);

pinMode( buzzer, OUTPUT);

dht.begin();

}
void loop()

float h = dht.readHumidity();

if(h>=80)

tone(buzzer,1000,500); // Send 1KHz sound signal...during 500ms

Serial.println("Alerte : l'humidité est supérieure ou égale a 80");

else

Serial.println("Info : l’humidité est inférieur à 80 ");

Exercice 3
#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT22

DHT dht(DHTPIN, DHTTYPE);

int MOTOR=4;
int led_rouge=3;
int led_verte=5;
void setup()
{
Serial.begin(9600);
pinMode(MOTOR, OUTPUT);
pinMode(led_verte,OUTPUT);
pinMode(led_rouge,OUTPUT);
dht.begin();
}

void loop()
{
float h = dht.readTemperature();
Serial.println(h);

if(h>28)
{
digitalWrite(MOTOR,HIGH);
Serial.println("Alerte : la température est supérieure a 28");
digitalWrite(led_verte,LOW);
digitalWrite(led_rouge,HIGH); }
else{
if(h>=27&&h<=28)
{
Serial.println("Info :la température entre 27 et 28");
digitalWrite(MOTOR,LOW);
digitalWrite(led_verte,LOW);
digitalWrite(led_rouge,LOW);
}
else
{
Serial.println("Info :la température est normal");
digitalWrite(MOTOR,LOW);
digitalWrite(led_rouge,LOW);
digitalWrite(led_verte,HIGH);
}
}
}

You might also like