5

First: Why would you need to measure the PWM value. You already know it; it's saved in the val variable. Why not just use this variable for later use in code? Second: Doing the analogRead on the same pin as the PWM output is not going to work. Internally there are 2 different hardware peripherals, that are responsible for these functions: The ADC is ...


3

The 9V wall adapter is in most cases a switched power regulator with a high frequency. That's like a radio transmitter direct beside the wire. So there is nothing mystical, when the smooth USB Voltage does not show problems but the "radio transmitter" does. There are two ways the power supply can impact: over radio wave or as ripples over the regulated ...


3

First, let me give a couple of suggestions on the programming style. There is no point in defining your own variables for accessing the hardware registers: the avr-libc does that for you, you just have to #include <avr/io.h>. Actually, you don't have to #include anything: the Arduino IDE automatically #includes Arduino.h, which in turn #includes avr/io....


3

You have two issues going on - noise pickup, and a potentiometer with imprecise stops at one or both ends. The pot is the easiest to fix: What are the lowest low reading and highest high reading you can reliably get when you turn it to its stops? Use those in place of '0' and '1023' in your map() function. Improving the noise is only slightly more involved....


3

You can use the output of your regulator as the reference voltage for your analog readings. That way, no matter what the voltage you voltage divider for the thermistor uses, the "upper" voltage that the ADC uses is always the same as the thermistor's voltage. Simply connect the output of the regulator to the AREF pin, and set the ADC to use the external ...


2

Take the regulator output to another analog input. Read that just before you read the thermistor. Use that voltage in your voltage divider calculation. The buzzer activity should be the same (ideally, off) during both readings.


2

You can't magic more resolution out of thin air (well, you can, but it slows down your sampling - you would "oversample" and average a number of sequential samples). Instead you need to boost your signal before it gets to the ADC using an op-amp. The simplest circuit (which also inverts the signal, but you don't really care about that I suspect) is: ...


2

If you want to measure a pin (i.e. defined as input pin, either digital or analog), you have to use a pull up or pull down resistor (either internal or external depending on what the MCU GPIOs have). This resistor makes sure in case there is nothing attached, that the (mostly high ohm) resistor will make sure the nonconnected pin will either give a LOW or ...


2

There are many ways to remove noise, below are some ways: Only change the value when it differs enough. Assume the range is 0-1023. Than only change the value if the input value differs more than a constant value (like 5 or 10, experiment with this to find a good value for your pot meter). Another way is to use the average of the last x readings, You can ...


2

What you are looking for is called the Thévenin equivalent source. For the schematic you are showing, and assuming you can neglect the output resistance of the battery itself, the output resistance of the voltage divider is the same as the two resistors in parallel. If you want the maximum allowed resistance (minimum current) you have then to solve: 1/R1 + ...


2

the Atmega328P's datasheet, it indicates the conversion factor is 5V/1024 [...] Indeed. And the datasheet is the only authoritative source. All the other sources are second-guessing. If Vin and Vref are 5V, then the ADC reading would need to be 1024 in order to have a true reading of 5V You can't get a true reading of 5 V. As per the datasheet (...


2

As others have said, the difference between 1023 and 1024 is quite small. However, the fact is that your input range for the ADC is 0 to 1023. (That's 1024 steps, but since it starts at 0, it won't go up to 1024) You'll get 0 at the minimum input, and 1023 at the maximum value. If you're using a 5.0V reference voltage and no voltage dividers, that means you ...


2

You should keep it uint16_t. See: analogRead. It shows the return value is a 10 bit number, which means a value of 0 to 1023. If you use uint8_t, which is an 8 bit value, it only can store values from 0-255. This means if the value is higher, the most significant bits are clipped/removed, and you only have the value module 256 left. With a 16 bit value, you ...


2

The DHT11 is a digital component with its own digital communication protocol. Analog pins can be used for either analog input or digital input and output. You can use a digital device like the DHT11 on any pin, whether it is labelled analog or digital (except on a couple of boards which have a few analog-only pins).


2

Your sketch works on a Nano (clone) that I have I am using a high-brightness white LED with a 10kΩ resistor to bring the brightness down to a bearable level, so the current drawn is about (5v-2.2v)/10kΩ = 0.28mA. This is a low level of current and should be safe for poking around with. I can see the embedded LED blink if I program the Pin 13, but no impact ...


2

The ADC measures a voltage ratio. The conversion result is the rounded value of 1024×V/Vref, where V is the voltage at the input and Vref is the voltage reference. In the default Arduino configuration, the reference is connected to Vcc. This will not fit your use case, as the voltage you want to read does not vary proportionately to Vcc. You could use an ...


1

ADC doesn't show the same value again You are not reading the ADC correctly, so ADC_READ() can return anything. See the comments in the code: word ADC_READ(byte sample, byte tim, byte CH) { word adcdata; // not needed word avrdata; // not initialized word abcdata; // not used byte i; for (i = 0; i < sample; i++) { ...


1

You cannot do what you are trying to do. There is no direct correspondence between some number of bits and a decimal digit. With hexadecimal, every 4 bits corresponds to exactly 1 hex digit. That is why hex is used for computers. One hex digit represents exactly 4 bits. Every time you add another hex digit, you add 4 bits. Two hex digits corresponds to ...


1

I cannot see, how your code would show the described behavior (assuming that, you have connected the buttons correctly with a pulldown resistor). But your code can be greatly simplified, which would make it less error prone. You have 8 buttons, which screams for the usage of arrays (IMO you should always use arrays, if you have more than 2 or 3 equal ...


1

The ESP is a 3.3v device. If your Uno is a 5v device, its A/D converter can measure and report voltages from 0 to 4.9878v (5v minus 1 LSB). If the same signal is presented to the ESP, any value above 3.29919 volts (3.3v - 1 LSB) will read as 4095, i.e., out of range. (If this isn't your issue, adding wiring diagrams of each system to your question will help ...


1

The ADC is a "Successive Approximation" type ADC. It works by: Taking a snapshot of the incoming voltage in a small capacitor Generating a reference voltage Comparing the voltage in the capacitor to that reference voltage Refining the reference voltage Go back to 3 until you have the accuracy you desire. There's lots of "time" involved there: The ...


1

The Kinesis 66 (the chip on the Teensy 3.6) has two ADC modules. Each one talks to different pins. By default the configuration functions in that library configure ADC0, so unless you tell it otherwise, you will only be configuring half the ADC pins. You should call each of the configuration functions twice, once for ADC0 and once for ADC1: adc->...


1

The AOUT pin of that device is no more than an amplified audio signal. It is AC coupled, and that means that it is a small signal varying around 0v. It is not suitable for feeding directly into an ADC. The AC coupling capacitor will be being charged up by the DC offset it is there to remove, and the lack of any drain on that capacitor while the ADC is not ...


1

Note that the Arduino function "map" is really this: long map(long x, long in_min, long in_max, long out_min, long out_max) { return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; } ...so, if you pass a "minimum from" value which is less than the actual value you are mapping from you will get a negative number given your "minimum out" ...


1

I solved the problem by adding 3 capacitors: 220uF on the Arduino power supply. 100uF on TL431 output. 1uF on A0 input. I also increased the sampling rate to 128 times (and removed the delay). Here's the result, as accurate as my multimeter: There's still 2mV difference in higher voltages which is because of my 2.5V reference voltage and Arduino ADC ...


1

You are sampling your audio signal with only 20Hz. That is very low frequency for an audio signal, that humans can hear. Generally you need to sample your signal with double of the highest containing frequency at minimum, or you will only get nonsense (you can google Nyquist Rate for more information). Also a Nano does not have a real DAC, so the audio is ...


1

The cause is the low sinking capabilities of LM35 output. This makes the output sensitive to EMI. Yes, the output output impedance is stated as 0.5 ohms but only for sourcing current. The sinking current is limited to 1uA which is easily achieved by the environment noise. You need to add a low impedance load between LM35 output and ground, can be 200 ohm ...


Only top voted, non community-wiki answers of a minimum length are eligible