Beginner questions getting LDR sensor working with Leonardo

Hello,

I signed up to the forum today. I am an absolute beginner, with no programming experience.
In part I am looking for help getting some things to work that I started with a friend, and perhaps I can learn some basic Arduino coding (less likely) along the way. I am not great at logica/technical stuff, Im a graphics designer, but who knows :slight_smile: I hope to get a better understanding of Arduino in the process, so here goes.

  • I have an Arduino Leonardo.
  • I have 5 LDR sensors connected to it, using a breadboard, with resistors between each. My friend made this as he is a little bit more knowledgeable
  • The LDR sensors (used to) send their voltage data via usb to use as midi in Ableton Live
  • This used to work until today, when I think I accidentally removed the sketch that was present and since I've tried reinstalling it, tried different libraries and got lost :slight_smile:

What I like to achieve (end goal) is to:

  • Have 1 or more LDR sensors which voltage data is sent via midi to Ableton live, where I can map it to musical controls (volume, pitch, etc) so it acts as a performance controller.
  • From Ableton, I also send these voltages to my modular synthesizer (works with voltages)
  • I also like the idea of adding distance sensors into the mix, but this can all be done later

Current situation:

  • I can get my Leonardo to be detected as a "device" in Ableton if I upload a sketch with a MIDIUSB library included, but it no longer seems to send data from the sensors (this worked before I messed up today).

My Questions to get started:

  • I have no idea where to start troubleshooting and getting things to work again
  • I don't know if a sketch or a midi usb library is needed to get the Leonardo to send over the data via USB. (or should this work by "default"?)
  • What is the function of the resistors in the setup? Does their value matter in the performance/scale output of the LDR?
  • Ableton has a Connection Toolkit that has built in support for Arduino, but I am unsure if this is supposed to work with the Leonardo or just the Uno? I tried to get its github sketch to work, but also no luck getting data to get sent. Connection Kit | Ableton
  • One thing (when it worked) I also ran into was that my LDRs only seemed to give off a very limited "range", eg. when mapped in Ableton Live to a control knob (0-100) it only moved 5 or 10% of the entire range. I think this is referred to as "scaling" but I haven't the faintest where to start.

Perhaps the best is to start from scratch, and build it up from there.

Appreciate your help and interest.

Thanks so much!

Chris

You are asking what is wrong with your system but you are not telling us anything technical about what you have.
In cases like this we need to know what you have in terms of a schematic at least.

Can you not get back to your friend and ask him to replace what you messed up?

Hi Mike,

I don't know how to make a schematic but here's a photo of how the LDRs are connected. However, since only things changed on the software side, I suspect the problem to be there, not in the breadboard connections.

I can get back to my friend, but I figured asking here gives me the chance to learn something so that I am perhaps not always dependent on others to get things to work (and keep it working).

That part of your circuit looks fine apart from the fact that it is on solderless bread board. That should only be used as a temporary prototype, it is not suitable for a permanent circuit. This is because the contacts corrode over a quite short time and it makes the connections intermittent. It should be built on strip board and fully soldered up.

Have you not got the original code from your normal backups of your computer, or the email your friend sent it to you in the first place?

Heya,

My friend's currently not responding, I asked for sure. However, as mentioned at the start, I like to learn a bit more about Arduino myself so that I don't have to rely on others as much and I like learning something new.

I've spent some time reading and watching Youtube videos on LDR projects and walked through some steps to check.

  • I can verify my LDR(s) are connected correct as per many Youtube videos and schematics.
  • My current sketch uses the AnalogReadSerial example to check if the LDRs are sending values. This works and in the Serial Monitor I see the values change per light value on the sensor

So I think I now need to make or expand my basic sketch so that it sends these values via USB to show up as MIDI in Ableton. I tried a few examples from the MIDIUSB library, but I didn't get any incoming signals in Ableton yet. I don't think I understand the coding syntax well enough yet, so this area is where I am asking for help now. :raised_hands:

If I can get this to work for 1 sensor, it would be easy to duplicate again for more sensors (Analog inputs 0-5).

cheers!

Chris

Please post it here using code tags when you do

So I have never programmed in my life, bear with me. What I like to do is take the varying voltage from the LDR sensor, and send that as a midi value via usb. In ableton I can use this value to control things. I tried looking at the examples included in the library, but couldn't make out how it works.

#include <USB-MIDI.h>

#include <pitchToFrequency.h>
#include <pitchToNote.h>
#include <frequencyToNote.h>
#include <MIDIUSB_Defs.h>
#include <MIDIUSB.h>

/*
  AnalogReadSerial

  Reads an analog input on pin 0, prints the result to the Serial Monitor.
  Graphical representation is available using Serial Plotter (Tools > Serial Plotter menu).
  Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.

  This example code is in the public domain.

  https://www.arduino.cc/en/Tutorial/BuiltInExamples/AnalogReadSerial
*/

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  
  // read the input on analog pin 5:
  int sensorValue = analogRead(A5);

  // print out the value you read:
  Serial.println(sensorValue);
  delay(1);        // delay in between reads for stability
  
  sendMIDI(midiEventPacket_t event);
}


I also found this page, that dives into it a little bit:

But when running this sketch, I get some errors, so again haha my noobness at play.

Cheers

Chris

What sort of MIDI messages do you want to send?
If it is control messages what controller numbers do you want to use?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.