W11 - Output DEVICES



To measure the analog and digital signals of a device with a multimeter you have turn the knob to the V~/- position and use the correct positive connection of the multimeter, plug the probes in parallel with the analog or digital pins of your device and turn it on.

We used an Arduino with the Analog Example Sketch to measure the analog output.

The results vary from 0v to 5v when turning the potentiometer up.

In the same way I used the Button Example Sketch to measure the digital output.

The results go from 0 to 1 when pressing the button.


As last week I´m going to do something not so fancy but useful for my final project.

For this week I’m controlling, with the Funduino, a Keyes SR1y Relay module circuit, and desolder the relay and create a new board for it.

Why a relay and not a mosfet, because I want to do it as close to the real thing as the time that I have allows me, so the circuit has to deal with from-the-plug AC current, and a relay can switch larger currents that a mosfet, and is a true ON/OFF switch.

First I’ll try everything as it is and then, to avoid uncertainty of ‘is it the program/is it the board’, and then mill a new board.

And it goes somethin’ like this or this.

Ok I´m told no photocoupler to start with, despite the fact that I want to do it as close to what I would really need for a real streetlamp. I’ll use 12V LED strip.

You can find the Files in W10 as the input output share shield.

The input and output are in the same board for convenience

I plugged 3 LED STRIPE and the EMERGENCY pin to pin 13 of the FUNDUINO and the rest as the schematic that follows.

At the beginning nothing happened, until I remembered that the COMON had to be wired from underneath to the COMON “on the back” near the the VCC pin.


Once I did…

#define RELAY_ON 1      // Define relay on pin state
#define RELAY_OFF 0     // Define relay off pin state

#define Relay  13       // Arduino pin where the relay connects

void setup()  
  digitalWrite(Relay, RELAY_OFF);      // initialise the relay to off
  pinMode(Relay, OUTPUT);   

void loop()         // Turn the relay on and off in sequence
  digitalWrite(Relay, RELAY_ON);  // turn the relay on
  delay(1000);                  // wait

  digitalWrite(Relay, RELAY_OFF); // turn the relay off
  delay(1000);                  // wait


When I combine Input and output in the same code (more details in W19) the delays eat 2.2 seconds (2x1000ms+20ms)!! Is absurd to have the loop stopped as the sensor should be read every 20ms not every 2.2s, and despite the fact that in the final configuration the lights are not expected to blink (hmmmm perhaps the gunshot light could) anyway I´m going to control the blinking through a PWM somehow. So as it uses the interna interrupts of th clocks it should not interfere (sensibly) the sensor reading.

I found a library that does what I want PWM lybrary

So I don’t have to mess with the clocks.

I tryed to installed as a zip, it gave me an error of library names must start with a letter or number and no weird chars. I deleted the spaces and dashes, still didnt work, it said Specified folder/zip file does not contain a valid library I unzipped and deleted all the example files, change the name to PWM.h and then rezipped it, Now it wokrks (Previously I had copied the unzipped folder in libraries directly and didnt work for the same reason).

Change emergency to signal of light for the relay

It worked!!! at he beginning it made a super high pitch noise, probably 1000 was too much frequency I set it to 100 and then to 1 and it turns the relay on and offers I have to remember that as we deal with frequencies, to get the former delay form 1000ms now I have to put 0.5Hz because it goes up and down in one cycle. Sadly this library sets frequency as an integer of 32 bits, I might try to change the lybrary to use a float, but as this is not really important for the project, only for testing the relay, I wont kill myself with t, in any case I can create an internal interrupt within a timer. How to interrupt

// Control the relay with pwm to avoid the dealying of the loop

#include <PWM.h>
int pin = 9;
int32_t frequency = 1;

void setup() {
  // put your setup code here, to run once:



void loop() {
  // put your main code here, to run repeatedly:
pwmWrite(pin, 127);

If I integrate the PWM control of the light in the code with the sensor reading WORKS AS EXPECTED!!! NO DELAY OF THE SENSOR READING!!!

Don’t switch the relay on off too many times or it will get damaged!!