Second lab on Arduino – ADaDeDuTon

In this laboratory, we used different functions from Arduino, of these functions:

  • pinMode
  • digitalWrite
  • digitalRead
  • analogWrite
  • analogRead

And the following functions for the communication with the monitor:

  • begin
  • println ()
  • write ()
  • read()
  • available

Different exercises were proposed to apply these functions. Depending on exercise, we chose the appropriate function.

 

Exercise 1:

Operation of the switch 3 pins:

It has 3 pins, a pin connected to GND (0V), a pin supplied with 5V and pin for reading the state (1 or 0) connected to an input of the Arduino.

For this first exercice, when the variables are declared, we used different functions. Firstly the serialbegin function to set the second bit data rate for the serial data transmission. Then the pinMode function to configure the specified pin to behave either as an input or output (pinMode (button, INPUT)).

The digitalRead function (button) was also used to read the state of the input connected and to save this state in an input variable. The Serial.println (ButtonState) function was used to display the data (1 or 0). A delay function () was used in the loop to repeat the loop all the 5ms

A condition if() was inserted to check that there is a state change

 

Exercise 2:

First of all there is a physical difference between a push button and a switch. The button consists of 4 pins connected 2 by 2 while the switch has 3 pins.

The electrical connection of the push button will be different from that of the switch. In addition, for the push button we need to integrate a resistor (pull-up resistor) connected to GND for receiving a clear signal of 0V. Otherwise external interferences may distort the signal 0V.

To display on the monitor if the button is pressed or not, we used the Serial.write function. This feature has been integrated into a “if” to analyze the state of the push button.

Using the pinMode function is assigned to an outlet for the lamp and an input to the push button. Then using the digitalRead function saves the state of one button, which will be used for the actuated or not the lamp using the digitalWrite function. We also used the delay function to avoid kickback.

 

Exercise 3:

To perform this exercise, we began by writting we equation to convert the voltage read in degrees thanks the equation of a straight line. To realize this straight line, we referred to the datasheet of the temperature sensor. Then we used the pinMode function to associate the pin input. Then we used the analogRead function to record the tension in a float. Finally we used the Serial.println fonction to display the temperature once it converted.

 

ADaDeDuTon

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s