This wiki has been archived and made read-only.
For up-to-date information about TkkrLab and it's projects please visit our main website at tkkrlab.nl.

Difference between revisions of "HowTo simple Arduino project"

From

Jump to: navigation, search
(On-off)
(Detailing)
Line 16: Line 16:
 
== Sensors ==
 
== Sensors ==
  
Sensors can be devided into three types: on-off, analog, and serial
+
There are three types of sensors that can be used with the Arduino to perform some kind of measurement or register an event in the environment. These are: on-off, analog, and serial.
  
 
=== On-off ===
 
=== On-off ===
Line 24: Line 24:
 
* Mechanical thermostat
 
* Mechanical thermostat
 
* [https://www.arduino.cc/en/Tutorial/TiltSensor Tilt sensor]
 
* [https://www.arduino.cc/en/Tutorial/TiltSensor Tilt sensor]
* Reed relais (activated by magnet)
+
* [http://www.instructables.com/id/Arduino-Reed-Switch/ Reed switch] (activated by magnet)
  
 
=== [https://www.arduino.cc/en/Tutorial/AnalogInput Analog] ===
 
=== [https://www.arduino.cc/en/Tutorial/AnalogInput Analog] ===
Line 31: Line 31:
  
 
Examples:
 
Examples:
 
 
* Potentiometer (to measure a rotary position)
 
* Potentiometer (to measure a rotary position)
 
* Photoresistor
 
* Photoresistor
Line 41: Line 40:
 
=== Serial (digital) ===
 
=== Serial (digital) ===
  
 +
There are sensors which return a numeric value by means of a serial protocol. A serial protocol consists of a sequence of pulses, where the lenght of the position of the pulses code a on-off (digital) value. The sequence of the on-off values represents a numeric value. Usually, the sensor is first send a signal to perform a measurement and then will respond with an answer. A number of commonly used protocols are:
 
* [https://nl.wikipedia.org/wiki/Serial_Peripheral_Interface SPI]
 
* [https://nl.wikipedia.org/wiki/Serial_Peripheral_Interface SPI]
 
* [https://en.wikipedia.org/wiki/I%C2%B2C I²C]
 
* [https://en.wikipedia.org/wiki/I%C2%B2C I²C]
 
* [https://en.wikipedia.org/wiki/1-Wire 1-Wire]
 
* [https://en.wikipedia.org/wiki/1-Wire 1-Wire]
* proprietary
 
 
Examples:
 
  
 +
Examples of such sensors are:
 
* [https://create.arduino.cc/projecthub/TheGadgetBoy/ds18b20-digital-temperature-sensor-and-arduino-9cc806 DS18B20 temperature sensor] (1-Wire)
 
* [https://create.arduino.cc/projecthub/TheGadgetBoy/ds18b20-digital-temperature-sensor-and-arduino-9cc806 DS18B20 temperature sensor] (1-Wire)
 
* [https://create.arduino.cc/projecthub/attari/temperature-monitoring-with-dht22-arduino-15b013 DHT-22 humidty and temperature sensor] (proprietary)
 
* [https://create.arduino.cc/projecthub/attari/temperature-monitoring-with-dht22-arduino-15b013 DHT-22 humidty and temperature sensor] (proprietary)
Line 55: Line 53:
 
* [http://mertarduinotutorial.blogspot.com/2017/01/arduino-tutorial-24-ds3231-real-time.html DS3231 Real Time Clock] (I²C)
 
* [http://mertarduinotutorial.blogspot.com/2017/01/arduino-tutorial-24-ds3231-real-time.html DS3231 Real Time Clock] (I²C)
 
* [https://www.arduino.cc/en/Tutorial/Ping Ping Ultrasonic Range Finder] (proprietary, delay)
 
* [https://www.arduino.cc/en/Tutorial/Ping Ping Ultrasonic Range Finder] (proprietary, delay)
 +
 +
=== Choicing the right type of sensor ===
 +
 +
Often it is the case that more than one type of sensor can be used to measure something, like for example the temperature. The choice depends on the kind of measurement one wants to do. Think about the resolution, the accuracy, and the frequence of the measurement.
  
 
== Actuators ==
 
== Actuators ==
  
Three types: on-off, analog, and serial
+
There are also three types of acturators that can be used in combination with the Arduino to cause some action or display some information: on-off, analog, and serial.
  
 
== On-off ==
 
== On-off ==
  
 +
The Arduino can be used to switch something on or off. Examples are:
 
* LED
 
* LED
 
* Relay shield
 
* Relay shield
Line 67: Line 70:
 
== Analog ==
 
== Analog ==
  
Not really analog: [https://en.wikipedia.org/wiki/Pulse-width_modulation Pulse-width modulation] (PWM)<br />
+
The Arduino can also give an 'analog' signal. It is not really analog, but uses
Arduino: 255 levels, 500Hz.
+
[https://en.wikipedia.org/wiki/Pulse-width_modulation Pulse-width modulation] (PWM) at a frequency of
 
+
500 pulses per second. The width of the pulses can be adjusted in 255 levels.  
 
+
  
 +
Examples of uses are:
 
* [https://www.arduino.cc/en/Tutorial/Fading LED fading]
 
* [https://www.arduino.cc/en/Tutorial/Fading LED fading]
 
* [https://www.arduino.cc/en/Tutorial/TransistorMotorControl Transitor Motor Control]
 
* [https://www.arduino.cc/en/Tutorial/TransistorMotorControl Transitor Motor Control]
Line 77: Line 80:
  
 
== Serial (digital) ==
 
== Serial (digital) ==
 +
 +
The Arduino can also send digital information through a serial protocol. These are
 +
often used to display information on a display.
  
 
=== Displays ===
 
=== Displays ===
  
 +
Types of displays are:
 
* [https://playground.arduino.cc/Main/MAX72XXHardware MAX7219 and MAX7221] (SPI) led drivers (matrix)
 
* [https://playground.arduino.cc/Main/MAX72XXHardware MAX7219 and MAX7221] (SPI) led drivers (matrix)
 
* [https://playground.arduino.cc/Code/LCD LCD displays] (many)
 
* [https://playground.arduino.cc/Code/LCD LCD displays] (many)
 
* [https://learn.adafruit.com/adafruit-neopixel-uberguide/arduino-library-use WS2812 RGB LED strips] NeoPixel ([https://www.tkkrlab.nl/wiki/LedPet LedPet])
 
* [https://learn.adafruit.com/adafruit-neopixel-uberguide/arduino-library-use WS2812 RGB LED strips] NeoPixel ([https://www.tkkrlab.nl/wiki/LedPet LedPet])
*
 
  
=== Others ===
+
=== Acturators ===
  
 +
Some examples are:
 
* [https://www.seeedstudio.com/Grove-I2C-Mini-Motor-Driver-p-2508.html I2C Mini Motor Driver]
 
* [https://www.seeedstudio.com/Grove-I2C-Mini-Motor-Driver-p-2508.html I2C Mini Motor Driver]
 
* [https://www.arduino.cc/en/Tutorial/Midi MIDI output] (to play music instrument)
 
* [https://www.arduino.cc/en/Tutorial/Midi MIDI output] (to play music instrument)

Revision as of 20:45, 5 June 2018

Simple Arduino sensor & acturator projects

The Arduino is an open hardware mircocontroller platform. A microcontroller can be used has the hart of a device that responds to an event by a certain action. Sensors are used to sense that a certain event or condition has occured. Acturators (including displays) are used to perform the action.

What?

A project starts with the formulation of a short description of what one want to achieve. Questions that need to be answered are

  • What do I want to sense?
  • What do I want to act or display?
  • With state or not? (Time words: after, when, ..)

An example of a stateless device is a light switch to switch a light on/off. An example of a device with a state is a lamp that is triggered by movement: the light goes on when some movement is detected and stays of until for 10 second no movement has been detected.

It is a good idea to draw a State Diagram, starting from the initial state and thinking about all the events/triggers that could happen. For each of this a line is drawn to a state. And then continue on with a state that has not been investigated yet. Whenever a state is reached that is equivalent to an earlier state, one can draw the line to that state.

Sensors

There are three types of sensors that can be used with the Arduino to perform some kind of measurement or register an event in the environment. These are: on-off, analog, and serial.

On-off

Examples of on-off sensors are:

Analog

The Arduino can measure a voltage between 0V and 5V with 1024 levels.

Examples:

Simple, but low resolution and/or accuracy.

Serial (digital)

There are sensors which return a numeric value by means of a serial protocol. A serial protocol consists of a sequence of pulses, where the lenght of the position of the pulses code a on-off (digital) value. The sequence of the on-off values represents a numeric value. Usually, the sensor is first send a signal to perform a measurement and then will respond with an answer. A number of commonly used protocols are:

Examples of such sensors are:

Choicing the right type of sensor

Often it is the case that more than one type of sensor can be used to measure something, like for example the temperature. The choice depends on the kind of measurement one wants to do. Think about the resolution, the accuracy, and the frequence of the measurement.

Actuators

There are also three types of acturators that can be used in combination with the Arduino to cause some action or display some information: on-off, analog, and serial.

On-off

The Arduino can be used to switch something on or off. Examples are:

  • LED
  • Relay shield

Analog

The Arduino can also give an 'analog' signal. It is not really analog, but uses Pulse-width modulation (PWM) at a frequency of 500 pulses per second. The width of the pulses can be adjusted in 255 levels.

Examples of uses are:

Serial (digital)

The Arduino can also send digital information through a serial protocol. These are often used to display information on a display.

Displays

Types of displays are:

Acturators

Some examples are:

Programing

Initialization and loop.

The loop:

  • Read sensors
  • Make decision (on state)
  • Activate acturators
  • Sleep

Program structure

Everything in a single file and libraries.

  • Include statements of libraries
  • Pin definitions
  • (Functions)
  • Initialization: void setup()
  • Loop: void loop()

Links